﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
// using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SAE_Storage_Admin
{
    public partial class Settings : Form
    {
        private Main mainForm;
        public Settings()
        {
            InitializeComponent();
        }

        public Settings(Main mainForm, String domain, String url)
        {
            InitializeComponent();
            this.mainForm = mainForm;
            tb_domain.Text = domain;
            tb_url.Text = url;
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            if (IsUrl(tb_url.Text))
            {
                String tmpUrl = tb_url.Text.Substring(tb_url.Text.LastIndexOf("/") + 1);
                if (tmpUrl.Equals("SEA_Storage_Admin.php"))
                {
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    if (MessageBox.Show("注意：您的服务器管理地址和默认地址相同，为了安全起见，请改名？", "请注意", buttons) == DialogResult.No)
                    {
                        mainForm.SaveSettings(tb_domain.Text, tb_url.Text);
                        this.Close();
                    }              
                }else{
                    mainForm.SaveSettings(tb_domain.Text, tb_url.Text);
                    this.Close();
                }
            }else{
                MessageBox.Show("请检查网络地址！");
            }
        }

        public bool IsUrl(string str_url)
        {
            return System.Text.RegularExpressions.Regex.IsMatch(str_url, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
        }

    }
}
